<template>
	<view>
		<view class="search-container-view">
			<view class="search-view">
				<image src="../../static/home_nav_search.png" class="icon"></image>
				<input placeholder="打针|换药" v-model="form.keyword"/>
				<image
					@click="cleanForm"
					v-if="showCleanBtn"
					src="../../static/searchbar_delete.png" 
					class="reset-btn"/>
				<view class="search-text" @click="refresh">搜索</view>
			</view>
		</view>
		<view class="list-view">
			<view class="list-item" v-for="item in list" @click="navToDetails(item)">
				<image :src="item.picImg"></image>
				<view class="right">
					<view class="title">{{item.proName}}</view>
					<view class="content three-line-ellipsis">{{item.proDes | htmlToTextFilters}}</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="status"></uni-load-more>
	</view>
</template>

<script>
import PageInfo from '../../utils/pageutils'
import * as medicalProjects from '../../common/api/medicalProjects.js'
	export default {
		data() {
			return {
				form:{
					keyword:''
				},
				pageInfo:new PageInfo(),
				list:[],
				status:'more',
			}
		},
		computed:{
			showCleanBtn(){
				return !!this.form.keyword
			}
		},
		onLoad() {
			this.refresh()
		},
		onPullDownRefresh() {
			this.refresh()
		},
		onReachBottom() {
			this.loadMore()
		},
		methods: {
			cleanForm(){
				this.form.keyword = ''
			},
			refresh(){
				this.pageInfo.reset()
				this.list = []
				this.status = 'loading'
				this.getList()
			},
			loadMore(){
				if(this.pageInfo.isNotLoadAll){
					this.status = 'loading'
					this.pageInfo.nextPage()
					this.getList()
				}else{
					this.status = 'noMore'
				}
			},
			getList(){
				const param = {
					pageIndex:this.pageInfo.pageIndex,
					pageSize:this.pageInfo.pageSize,
					keyWords:this.form.keyword
				}
				medicalProjects.queryByPage(param).then(result => {
					const list = result.data.data.rows || []
					const total = result.data.data.total
					this.list = [...this.list,...list]
					this.pageInfo.total = total
					this.pageInfo.loadedTotal = this.list.length
					setTimeout(()=>{
						if(this.pageInfo.isNotLoadAll){
							this.status = 'more'
						}else{
							this.status = 'noMore'
						}
						uni.stopPullDownRefresh()
					},200)
				}).catch(error => {
					console.log(error);
				})
			},
			navToDetails(item){
				uni.navigateTo({
					url:'/patientAppPages/pages/serviceDetails/serviceDetails?uid='+item.uid
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
	.search-container-view{
		width: 100%;
		padding: 10rpx 20rpx;
		box-sizing: border-box;
		.search-view{
			width: 100%;
			height: 64rpx;
			background: white;
			border-radius: 32rpx;
			display: flex;
			align-items: center;
			padding-left: 20rpx;
			padding-right: 20rpx;
			box-sizing: border-box;
			border: solid 2rpx #0BC5AE;
			.icon{
				width: 40rpx;
				height: 40rpx;
			}
			input{
				height: 100%;
				flex: 1;
				font-size: 26rpx;
				margin-left: 10rpx;
				margin-right: 10rpx;
			}
			.reset-btn{
				width: 36rpx;
				height: 36rpx;
				margin-right: 30rpx;
			}
			.search-text{
				font-size: 30rpx;
				color: #0BC5AE;
			}
		}
	}
	
	.list-view{
		margin-left: 20rpx;
		margin-right: 20rpx;
		background: white;
		border-radius: 16rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		margin-top: 30rpx;
		.list-item{
			display: flex;
			padding: 20rpx 0;
			box-sizing: border-box;
			border-bottom: solid 2rpx #F8F8F8; 
			image{
				width: 174rpx;
				height: 174rpx;
				border-radius: 20rpx;
			}
			.right{
				display: flex;
				flex-direction: column;
				flex: 1;
				margin-left: 20rpx;
				justify-content: space-around;
				.title{
					font-size: 32rpx;
					font-weight: bold;
					color: #232323;
				}
				.content{
					font-size: 26rpx;
					color: rgba(35,35,35,0.7);
				}
			}
		}
	}

	
</style>
